Skip to content

Add Tree::wakeUpSignal() getter#1127

Open
tonynajjar wants to merge 3 commits intoBehaviorTree:masterfrom
botsandus:add-sleep-override
Open

Add Tree::wakeUpSignal() getter#1127
tonynajjar wants to merge 3 commits intoBehaviorTree:masterfrom
botsandus:add-sleep-override

Conversation

@tonynajjar
Copy link
Copy Markdown

@tonynajjar tonynajjar commented Apr 4, 2026

Problem

Tree::sleep() uses WakeUpSignal::waitFor(), which internally calls std::condition_variable::wait_for() — this always measures time against steady_clock (wall time). When using a simulated clock that runs faster or slower than real time (e.g., ROS 2's /clock topic with use_sim_time), the tree tick rate doesn't scale with the simulation. At 10x sim speed, a 100ms loop timeout still blocks 100ms real time, so the tree ticks 10x too slowly relative to the simulated world.

C++ provides no mechanism to make condition_variable wait on a custom clock, so any solution requires polling.

Solution

Add Tree::wakeUpSignal() — a simple getter that returns the tree's shared WakeUpSignal. This allows frameworks to implement their own clock-aware sleep logic externally while still being able to check for wake-up signals (preemption).

For example, in ROS 2 (Nav2), the between-tick sleep loop can poll the ROS clock for the deadline while doing short waitFor(1ms) calls to stay responsive to preemption:

auto wake_up = tree->wakeUpSignal();
while (ros_clock->now() < deadline) {
  if (wake_up->waitFor(std::chrono::milliseconds(1)))
    return true;  // woken up early
}

Signed-off-by: Tony Najjar <tony.najjar@dexory.com>
Signed-off-by: Tony Najjar <tony.najjar@dexory.com>
Signed-off-by: Tony Najjar <tony.najjar@dexory.com>
@tonynajjar tonynajjar changed the title Add Tree::setSleepOverride() for custom clock-aware sleeping Add Tree::wakeUpSignal() getter Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant